package cn.tools;

import cn.pojo.Backend_user;
import cn.pojo.Dev_user;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;

public class AuthInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String uri=request.getRequestURI();
    if(uri.indexOf("/dev/from")!=-1||uri.indexOf("/dev/login")!=-1
            ||uri.indexOf("/backend/from")!=-1||uri.indexOf("/backend/login")!=-1||uri.indexOf("/out/logout")!=-1){
    return true;
}
        if ((Dev_user) request.getSession().getAttribute(Constants.DEV_SESSION)==null&&(Backend_user) request.getSession().getAttribute(Constants.USER_SESSION)==null) {
            //return "redirect:/login.jsp";
            response.sendRedirect("../404.jsp");
            return false;
        }
        return true;
    }
}
